var currentPage = 1;
var pageSize = 4;
var sumPage = 1;

let times = "";

function pageInfo(time) {
    times = time;
    $(".layui-timeline").html("&nbsp;")
    let json = {
        'event':$('#evnet').val(),
        'time': time,
        'currentPage': currentPage,
        'pageSize': pageSize
    }
    console.log(json);
    $.ajaxSettings.async = false;
    $.getJSON("/log/show", json, function (data) {
        console.log(data);
        if (data.list == ''){
            layer.msg(time+" 无日志信息！");
        }

        $(data.list).each(function (i, v) {
            let date = new Date(v.createtime);
            let m = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
            let d = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate())
            let s = date.getHours();
            let f = date.getMinutes();
            let ms = date.getSeconds();
            let time = date.getFullYear() + "-" + m + "-" + d + ' ' + s + ':' + f + ':' + ms;
            let content = '<li class="layui-timeline-item">\n' +
                '                    <i class="layui-icon layui-timeline-axis">&#xe63f;</i>\n' +
                '                    <div class="layui-timeline-content layui-text">\n' +
                '                        <h3 class="layui-timeline-title">' + time + '</h3>\n' +
                '                        <p> ' + v.user.name + ' <br> ' + v.jobtitle.job + '<br> ' + v.event + ' ' +
                '                        </p>\n' +
                '                    </div>\n' +
                '                </li>'
            $(".layui-timeline").append(content);
        })
        if (data.pages == 0) {
            sumPage = 1;
        }else {
            sumPage = data.pages;
        }
    });
    $(".yeshu").text("第" + currentPage + "页/共" + sumPage + "页");
    $.ajaxSettings.async = true;

}

function next() {
    currentPage = currentPage + 1;
    if (currentPage > sumPage) {
        currentPage = sumPage;
        layer.msg("最后一页啦");
        return;
    }
    pageInfo(times);
}

function prev() {
    currentPage = currentPage - 1;
    if (currentPage < 1) {
        currentPage = 1;
        layer.msg("前面没有啦")
        return;
    }
    pageInfo(times);
}

function end() {
    currentPage = sumPage
    pageInfo(times);
}

function start() {
    currentPage = 1
    pageInfo(times);
}

// laydate.render({
//     elem: '#timeTans'
//     ,position: 'static'
// });